package org.eenie.commonlib.ui.splash;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.AppUtils;
import com.eenie.common.base.BaseActivity;
import com.eenie.common.base.WinMode;
import com.eenie.common.utils.TimeCounter;

import org.eenie.commonlib.R;
import org.eenie.commonlib.ui.MainActivity;

import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;


/**
 * 展示闪屏页功能设计，适配非16：9的屏幕
 */
public class SplashActivity extends BaseActivity implements TimeCounter.TimerCounterListener {
    ImageView mImgSplash;

    TextView mTvVer;

    TimeCounter mTimeCounter;

    TextView mTvCount;

    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("s");

    @Override
    public int initContentView() {
        return R.layout.activity_splash;
    }

    @Override
    public void initInjector() {
        setWinMode(WinMode.IMMERSE);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE);
        setNavigationBarColor(Color.TRANSPARENT);

        mTimeCounter = new TimeCounter(1, TimeUnit.SECONDS, true);
        mTimeCounter.bindLifecycle(this);
        mTimeCounter.setTimerCounterListener(this);

    }

    @Override
    public void initUiAndListener(View view) {
        mTvCount = findViewById(R.id.tv_count);
        mTvVer = findViewById(R.id.tv_ver);
        mImgSplash = findViewById(R.id.img_splash);


        mTvVer.setText("v" + AppUtils.getAppVersionName());
        mTimeCounter.startCount();
    }




    @Override
    public void onTick(long curTime, long tolTime) {
        mTvCount.setText(mSimpleDateFormat.format(curTime));
    }

    @Override
    public void onComplete() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }


}
